home *** CD-ROM | disk | FTP | other *** search
- #define TEXT_TABLE "Text Table.txt"
- #include <vdbase.h>
- #define NAVIGATE_NEXT 1
- #define NAVIGATE_FIRST 2
- #define NAVIGATE_LAST 3
- #define STATE_CLOSED 0
- #define STATE_EDIT 2
- #define STATE_APPEND 3
- ** END HEADER -- do not remove this line
- //
- // Generated on 09/23/97
- //
- class TextTableDataModule of DATAMODULE
-
-
- this.TEXTQUERY = new QUERY()
- this.TEXTQUERY.parent = this
- with (this.TEXTQUERY)
- onClose = class::CLOSETEXT
- left = 0
- top = 0
- sql = "select * from TextTable.txt"
- execute = class::OPENTEXT
- active = true
- endwith
-
-
- with (this.TEXTQUERY.rowset)
- last = class::LASTTEXT
- next = class::NEXTTEXT
- first = class::FIRSTTEXT
- goto = class::GOTOTEXT
- bookmark = {; return this.cursor}
- beginAppend = class::APPENDTEXT
- delete = class::DELETETEXT
- save = class::SAVETEXT
- count = class::COUNTTEXT
- lockRow = {||true}
- endwith
-
-
- // {Linked Method} form.textquery.execute
- function openText
- local f, bOpen
- f = new Field()
- bOpen = true
- this.session := null
- this.file = new File()
- this.rowset.cursor = 1
- try
- this.file.open( TEXT_TABLE, "R" )
- with ( f )
- fieldName := "TextField"
- length := 50
- value := this.file.readln()
- endwith
- f.onChange = { ; this.parent.parent.modified := true}
- this.rowset.fields.add( f )
- this.rowset.fields[1].baseValue = f.value
- if ( this.file.eof() )
- this.rowset.endOfSet := true
- else
- this.rowset.cursor := 1
- endif
- this.rowset.state := STATE_EDIT
- catch ( Exception e )
- bOpen := false
- this.rowset.state := STATE_CLOSED
- with ( f )
- fieldName := "TextField"
- length := 50
- value := "Error: Unable to open 'Text Table.txt'"
- endwith
- this.rowset.fields.add( f )
- endtry
- return ( bOpen )
-
- // {Linked Method} form.textquery.onClose
- function closeText
- if ( not this.rowset.state == STATE_CLOSED )
- this.file.close()
- endif
- return true
-
- // {Linked Method} form.textquery.rowset.next
- function nextText( nOffset )
- local sValue, bNext
- bNext = true
- if ( not this.state == STATE_CLOSED )
- ROWSET::NEXT()
- sValue = null
- this.endOfSet := false
- if ( PCOUNT() == 0 )
- nOffset = 1
- endif
- if ( nOffset > 0 )
- // forward movement
- for i = 1 to nOffset
- if this.parent.file.eof()
- this.endOfSet := true
- nOffset := 0
- else
- sValue := this.parent.file.readln()
- endif
- this.cursor++
- next
- else
- // backward movement
- if ( this.cursor + nOffset ) > 0
- this.parent.file.seek( 0, FILE_BEGIN )
- this.cursor := (this.cursor + nOffset )
- for i = 1 to this.cursor
- sValue := this.parent.file.readln()
- next
- else
- // attempt to go before first row.
- this.cursor := 0
- this.endOfSet := true
- this.parent.file.seek( 0, FILE_BEGIN )
- endif
- endif
- with ( this.fields[1] )
- value := sValue
- baseValue := sValue
- endwith
- this.modified := false
- this.refreshControls()
- bNext := ( not this.endOfSet )
- endif
- return ( bNext )
-
- // {Linked Method} form.textquery.rowset.first
- function firstText
- if ( not this.state == STATE_CLOSED )
- ROWSET::FIRST()
- this.parent.file.seek( 0, FILE_BEGIN )
- this.cursor := 0
- class::nextText()
- endif
- return true
-
- // {Linked Method} form.textquery.rowset.last
- function lastText
- local sValue
- if ( not this.state == STATE_CLOSED )
- ROWSET::LAST()
- sValue = null
- this.parent.file.seek( 0, FILE_BEGIN )
- this.cursor = 0
- do while ( NOT this.parent.file.eof() )
- sValue := this.parent.file.readln()
- this.cursor++
- enddo
- with ( this.fields[1] )
- value := sValue
- baseValue := sValue
- endwith
- this.modified := false
- this.refreshControls()
- endif
- return true
-
- // {Linked Method} form.textquery.rowset.save
- function saveText
- if ( not this.state == STATE_CLOSED )
- ROWSET::SAVE()
- this.modified := false
- do case
- case ( this.state == STATE_EDIT )
- class::rewriteText( this.fields[1].value )
- case ( this.state == STATE_APPEND )
- this.parent.file.seek( 0, FILE_END )
- this.parent.file.writeln( this.fields[1].value )
- this.fields[1].baseValue := this.fields[1].value
- this.state := STATE_EDIT
- class::lastText()
- endcase
- endif
- return true
-
- // {Linked Method} form.textquery.rowset.goto
- function gotoText( nCursor )
- local nGoto, bGoto
- bGoto = true
- if ( not this.state == STATE_CLOSED )
- nGoto = ( nCursor )
- class::firstText()
- if ( nGoto > 1 )
- class::nextText( nGoto - 1 )
- endif
- bGoto := ( not this.endOfSet )
- endif
- return ( bGoto )
-
- // {Linked Method} form.textquery.rowset.count
- function countText
- local nCount, nCurrent
- nCount = 0
- if ( not this.state == STATE_CLOSED )
- nCurrent = this.parent.file.seek( 0, FILE_CURRENT )
- this.parent.file.seek( 0, FILE_BEGIN )
- do while ( NOT this.parent.file.eof() )
- this.parent.file.readln()
- nCount++
- enddo
- this.parent.file.seek( nCurrent, FILE_BEGIN )
- endif
- return nCount
-
- // {Linked Method} form.textquery.rowset.delete
- function deleteText
- if ( not this.state == STATE_CLOSED )
- class::rewriteText( null )
- class::gotoText( this.cursor )
- endif
- return true
-
- function rewriteText( xValue )
- local sTemp, sText, sValue
- local tmpFile
- local nTempCursor, nPosition
- sTemp = FUNIQUE() + ".TXT"
- sText = this.parent.file.path
- tmpFile = new File()
- tmpFile.create( sTemp, "RW" )
- nTempCursor = 0
- nPosition = 0
- this.parent.file.seek( 0, FILE_BEGIN )
- do while ( NOT this.parent.file.eof() )
- sValue = this.parent.file.readln()
- nTempCursor++
- if ( nTempCursor == this.cursor )
- if ( xValue == null )
- nPosition := this.parent.file.position
- else
- tmpFile.writeln( xValue )
- nPosition := tmpFile.position
- endif
- else
- tmpFile.writeln( sValue )
- endif
- enddo
- this.parent.file.close()
- tmpFile.close()
-
- try
- tmpFile.delete( sText )
- tmpFile.copy( sTemp, sText )
- tmpFile.delete( sTemp )
- catch ( Exception e )
- MSGBOX( e.message, "Alert", 0 + 48 )
- endtry
-
- this.parent.file.open( sText, "R" )
- this.parent.file.seek( nPosition, FILE_BEGIN )
- return true
-
- // {Linked Method} form.textquery.rowset.beginAppend
- function appendText
- if ( not this.state == STATE_CLOSED )
- with ( this.fields[1] )
- value := SPACE(0)
- baseValue := SPACE(0)
- endwith
- this.modified := true
- this.refreshControls()
- this.state := STATE_APPEND
- endif
- return true
- endclass
-